<template>
  <div id="medical_details">
    <header>
      <span @click="goBack()">返回</span>
      <div>病历详情</div>
      <!-- <span @click='edit_medical' v-if="!infoObj.sign||name=='clinic'">编辑</span> -->
      <span @click='edit_medical'>编辑</span>
    </header>
    <div class="order" v-if="name=='clinic'&&show" @click="send()">
      发给医生
    </div>
    <div>
      <ul>


        <li>
          <span>就诊时间:</span>
          <i>{{infoObj.time}}</i>
        </li>
        <li class='noBack' v-if="name=='clinic'">
          <span>配台护士:</span>
          <i>{{infoObj.nurse || "无"}}</i>
        </li>

        <li>
          <span>类型:</span>
          <i>{{infoObj.menu}}</i>
        </li>
        <li>
          <span>主诉:</span>
          <i>{{infoObj.complaint || "无"}}</i>
        </li>
        <li>
          <span>现病史:</span>
          <i>{{infoObj.current || "无"}}</i>
        </li>
        <li>
          <span>既往史:</span>
          <i>{{infoObj.history || "无"}}</i>
        </li>
        <li>
          <span>检查:</span>

          <i>{{infoObj.inspection || "无"}}</i>
        </li>
        <li>
          <span>辅助检查:</span>

          <i>{{infoObj.assist_check || "无"}}</i>
        </li>
        <li style="border-bottom: 0px">
          <span>影响资料:</span>
        </li>
        <li class="fzcheck" style="margin-top: -11px;border-bottom: 0px">
          <img :src="val" alt="" v-for="(val,index) in relPic">
          <!-- <img :src="" alt=""> -->
        </li>
        <li style="margin-top:10px;border-top: 1px solid #dfdfdf">
          <span>诊断:</span>
          <i>{{infoObj.diagnose || "无"}}</i>
        </li>
        <li>
          <span>治疗方案:</span>
          <i>{{infoObj.treatment || "无"}}</i>
        </li>
        <li>
          <span>治疗:</span>
          <i>{{infoObj.cure || "无"}}</i>
        </li>

        <li>
          <span>医嘱:</span>
          <i>{{infoObj.advice || "无"}}</i>
        </li>
        <li>
          <span>医生签字:</span>
          <i>{{infoObj.sign || "无"}}</i>
        </li>
        <li v-if="name=='clinic'">
          <span>医生注册手机号:</span>
          <input type="number" v-model="doctornumber" placeholder="请填写医生注册的手机号">
        </li>
      </ul>


    </div>
  </div>
</template>
<script>
  export default {
    data() {
      return {
        pid: '', //患者id
        id: '', //病历id
        doctorname: '', //医生姓名
        doctornumber: '', //发给医生id
        status: '',
        relPic: '', //辅助检查
        show: true,
        infoObj: {},
        name: '',
        number: '',
        params: {
          doctorname: '', //医生姓名
          doctor_id: '', //发给医生id
          id: '',
        }
      }
    },
    methods: {
      //返回上一级
      goBack() {
        if (this.$route.query.status == '1') {
          this.$router.push({
            name: 'medical_records1',
            query: {
              pid: this.pid
            }
          });
        } else {
          this.$router.push({
            name: 'medical_records',
          });
        }
      },
      send() {
        console.log(this.infoObj.sign)
        if (this.infoObj.sign != '' && this.infoObj.sign != null) {
          this.$utils._toast("该病历已签字");
          return;
        }
        if (this.name == 'clinic') {
          if (!this.doctornumber) {
            this.$utils._toast("请输入医生注册时的手机号");
            return false;
          } else if (!/^1(3|4|5|7|8|9)\d{9}$/.test(this.doctornumber)) {
            this.$utils._toast("手机号码有误，请重填");
            return false;
          }
        }
        this.params.id = this.id;
        this.params.doctorname = this.doctorname;
        this.params.doctor_id = this.doctornumber;
        this.$api.post(this.$api.baseURLSchool, "/update/medical_records", this.params, r => {
          if (r.data.ret == -1) {
            this.$utils._toast(r.data.errinfo.errmsg);
          }
          if (r.data.ret == 1) {
            // this.show = false
            this.$utils._toast('发送成功');
            this.getDetailsData();
          }
        }, err => {
          console.log(err);
        })
      },
      getDetailsData() {
        if (this.$route.query.pid == undefined) {
          this.pid = localStorage.getItem('pid'); //患者id
        } else {
          this.pid = this.$route.query.pid; //患者id
        }
        this.status = this.$route.query.status;
        localStorage.removeItem('blid');
        localStorage.removeItem('bldoctorname');
        this.id = this.$route.query.id //病历id
        this.$api.get(this.$api.baseURLSchool, "select_cid/medical_records/" + this.id, {}, r => {
          if (r.data.ret == 1) {
            this.infoObj = r.data.info;
            this.doctornumber = r.data.info.doctor_id;
            this.relPic = JSON.parse(r.data.info.relPic)
          }
        }, err => {
          console.log(err);
        })
      },
      //编辑病历
      edit_medical() {
        this.$router.push({
          name: 'edit_medical',
          query: {
            status: 'edit',
            id: this.id
          }
        });
      },

    },
    created() {
      this.doctorname = this.$route.query.doctorname;
      this.name = JSON.parse(localStorage.getItem('type'))
      this.getDetailsData();
    },

  }

</script>
<style lang="scss" scoped>
  input {
    border: transparent;
  }



  .fzcheck img {
    width: 47px;
    height: 47px;
    margin: 5px;

  }

</style>
